import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

import Layout from '@/layout'
import LayoutHeader from "@/layoutHeader"
export const constantRoutes = [{
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/course",
      name:"智慧体育课堂",
      component: () => import('@/views/layoutHeader/course'),
      active:"1"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/createCourse",
      name:"创建体育课",
      component: () => import('@/views/layoutHeader/createCourse'),
      active:"1"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/AiHomework",
      name:"ai体锻作业",
      component: () => import('@/views/layoutHeader/AiHomework'),
      active:"2"
    }]
  },
 {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/newlearningAssignments",
      name:"检查作业",
      component: () => import('@/views/layoutHeader/newlearningAssignments'),
      active:"2"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/plan/planNewAdd",
      name:"添加模板",
      component: () => import('@/views/layoutHeader/plan/planNewAdd'),
      active:"2"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/follow",
      name:"跟着学",
      component: () => import('@/views/layoutHeader/follow'),
      active:"2"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/plan",
      name:"计划作业",
      component: () => import('@/views/layoutHeader/plan'),
      active:"2"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/newfollowThePractice",
      name:"AI体锻作业计划",
      component: () => import('@/views/layoutHeader/newfollowThePractice'),
      active:"2"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/newstudyAssignments",
      name:"跟着学计划",
      component: () => import('@/views/layoutHeader/newstudyAssignments'),
      active:"2"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/planList",
      name:"体育作业计划",
      component: () => import('@/views/layoutHeader/plan/index2'),
      active:"2"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/newexamine",
      name:"检查作业",
      component: () => import('@/views/layoutHeader/newexamine'),
      active:"2"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/particulars",
      name:"作业详情",
      component: () => import('@/views/layoutHeader/newexamine/component/particulars.vue'),
      active:"2"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/classMessage",
      name:"班级详情",
      component: () => import('@/views/layoutHeader/classMessage'),
      active:"1"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/createSchoolSource",
      name:"上传资源",
      component: () => import('@/views/layoutHeader/createSchoolSource'),
      active:"1"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/schoolSource",
      name:"创建体育课",
      component: () => import('@/views/layoutHeader/schoolSource'),
      active:"1"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/student",
      name:"学生管理",
      component: () => import('@/views/layoutHeader/student'),
      active:"1"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/class",
      name:"我的班级",
      component: () => import('@/views/layoutHeader/class'),
      active:"1"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/devices",
      name:"设备列表",
      component: () => import('@/views/layoutHeader/devices'),
      active:"1"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/play",
      name:"体育云赛事",
      component: () => import('@/views/layoutHeader/play'),
      active:"3"
    }]
  },
  {
    path:'/teacherLayout',
    component:LayoutHeader,
    children: [{
      path:"/sportwork",
      name:"体育作业",
      component: () => import('@/views/layoutHeader/sportWork'),
      active:"2"
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/welcome',
    component: () => import('@/views/welcome'),
    hidden: true
  },
  {
    path: '/welcomeG',
    component: () => import('@/views/welcomeGuangxi'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [{
      path: 'index',
      name: '首页',
      component: () => import('@/views/index/index'),
      meta: {
        title: '工作台',
        icon: 'icon-a-gongzuotaigongzuozhuo-10'
      },
    }]
  },
  // 跟着练
  {
    path: '/follow',
    component: Layout,
    children: [{
      path: 'followThePractice',
      name: '跟着练',
      component: () => import('@/views/followThePractice/index'),
      meta: {
        title: '跟着练',
        icon: 'icon-zuoyejilu',
      }
    }]
  },
  //教师资源
  {
    path: '/teacherSource',
    component: Layout,
    hidden:true,
    children: [{
      path: 'followThePractice',
      name: '教学资源',
      component: () => import('@/views/teacherSource/index'),
      meta: {
        title: '教学资源',
        icon: 'icon-zuoyejilu'
      }
    }]
  },
    //体教管理
    {
      path: '/physicalEducation',
      component: Layout,
      hidden:true,
      children: [{
        path: 'physicalEducation',
        name: '体教管理',
        component: () => import('@/views/physicalEducation/index'),
        meta: {
          title: '体教管理',
          icon: 'icon-zuoyejilu'
        }
      }]
    },
  // 学习作业
  {

    path: '/studyAssignments',
    component: Layout,
    name: '学习作业',
    meta: {
      title: '学习作业',
      icon: 'icon-xuexiaoguanli'
    },
    children: [{
        path: 'uploadstudyAssignments',
        name: '上传',
        component: () => import('@/views/studyAssignments/uploadstudyAssignments'),
        meta: {
          title: '上传学习作业'
        },
      },
      {
        path: 'studyAssignments',
        name: '上传',
        component: () => import('@/views/studyAssignments/studyAssignments'),
        meta: {
          title: '学习作业列表'
        },
      },

      {
        path: 'learningAssignments',
        name: '上传',
        component: () => import('@/views/studyAssignments/learningAssignments'),
        meta: {
          title: '检查学习作业'
        },
      },
    ]
  },
  {
    path: '/school',
    component: Layout,
    name: '学校',
    meta: {
      title: '学校管理',
      icon: 'icon-xuexiaoguanli'
    },
    children: [{
        path: 'teacher',
        name: '教师',
        component: () => import('@/views/school/teahcer'),
        meta: {
          title: '教师管理'
        },
      },
      {
        path: 'grade',
        name: '年级',
        component: () => import('@/views/school/grade'),
        meta: {
          title: '年级管理'
        }
      },
      {
        path: 'class',
        name: '班级',
        component: () => import('@/views/school/class'),
        meta: {
          title: '班级管理'
        },
      },
      {
        path: 'student',
        name: '学生',
        component: () => import('@/views/school/student'),
        meta: {
          title: '学生管理'
        }
      },
    ]
  },
  {
    path: '/sports',
    component: Layout,
    name: '体育',
    meta: {
      title: '体育作业',
      icon: 'icon-zuoyejilu'
    },
    children: [{
        path: 'plan',
        name: '作业计划',
        component: () => import('@/views/sports/plan'),
        meta: {
          title: '作业计划'
        }
      },

      {
        path: 'examine',
        name: '检查作业',
        component: () => import('@/views/sports/examine'),
        meta: {
          title: '检查作业'
        }
      },
      {
        path: 'particulars',
        name: '作业详情',
        component: () => import('@/views/sports/examine/component/particulars'),
        hidden: true,
        meta: {
          title: '作业详情'
        }
      },
      {
        path: 'exercise',
        name: 'AI运动处方',
        component: () => import('@/views/sports/plan/components/exercise'),
        meta: {
          title: 'AI运动处方'
        }
      },
      {
        path: 'Aplan',
        name: '发起计划',
        component: () => import('@/views/sports/plan/Aplan'),
        hidden: true,
        meta: {
          title: '发起计划'
        }
      },
      {
        path: 'planAdd',
        name: '添加模板',
        component: () => import('@/views/sports/plan/planAdd'),
        hidden: true,
        meta: {
          title: '添加作业模板'
        }
      },
    ]
  },
  {
    path: '/regionalManagers',
    component: Layout,
    name: '客户经理列表',
    meta: {
      title: '客户经理列表',
      icon: 'icon-xuexiaoguanli'
    },
    children: [{
      path: 'index',
      name: '客户经理列表',
      component: () => import('@/views/regionalManagers/index'),
      meta: {
        title: '客户经理列表'
      }
    }, ]
  },
  {
    path: '/regionalManager',
    component: Layout,
    name: '客户商机',
    meta: {
      title: '客户商机',
      icon: 'icon-xuexiaoguanli'
    },
    children: [{
      path: 'index',
      name: '客户商机',
      component: () => import('@/views/regionalManager/index'),
      meta: {
        title: '客户商机'
      }
    }, ]
  },
  {
    path: '/customerManager',
    component: Layout,
    name: '客户商机',
    meta: {
      title: '客户商机',
      icon: 'icon-xuexiaoguanli'
    },
    children: [{
      path: 'index',
      name: '客户商机',
      component: () => import('@/views/customerManager/index'),
      meta: {
        title: '客户商机'
      }
    }, ]
  },
  {
    path: '/administrator',
    component: Layout,
    name: '学校管理',
    meta: {
      title: '学校管理',
      icon: 'icon-xuexiaoguanli'
    },
    children: [{
      path: 'index',
      name: '学校管理',
      component: () => import('@/views/administrator/index'),
      meta: {
        title: '学校管理'
      }
    }, ]
  },
  {
    name: "体育赛事",
    path: '/sportsK',
    component: Layout,
    meta: {
      title: '体育赛事',
      icon: 'icon-jiangbei'
    },
    hidden: false,
    children: [{
        path: 'sportsK',
        name: '体育赛事',
        component: () => import('@/views/sportsEvent/index'),
        meta: {
          title: '体育赛事'
        },
      },
      {
        path: 'achievement',
        name: '成绩汇总',
        component: () => import('@/views/achievement/index'),
        meta: {
          title: '成绩汇总'
        }
      },
    ]
  },
  {
    name: "活动管理",
    path: '/activea',
    component: Layout,
    meta: {
      title: '活动管理',
      icon: 'icon-jiangbei'
    },
    hidden: true,
    children: [
      {
        path: 'active',
        name: '活动列表',
        component: () => import('@/views/active/index'),
        meta: {
          title: '活动列表'
        }
      },
    ]
  },
  {
    path: '/sportsVideo',
    component: Layout,
    redirect: '/sportsVideo',
    hidden: true,
    children: [{
      path: 'sportsVideo',
      name: '体育',
      component: () => import('@/views/videoBases/index'),
      meta: {
        title: '视频库',
        icon: 'icon-shipin'
      }
    }]
  },
  {

    path: '/sportsConsulting',
    component: Layout,
    name: '体育',
    meta: {

      title: '体育资讯&知识',
      icon: 'icon-shipin'
    },
    children: [{
        path: 'information',
        name: '体育咨询',
        component: () => import('@/views/information/index'),
        meta: {
          title: '体育资讯&知识'
        }
      },
      {
        path: 'infoForm',
        name: '添加体育咨询',
        component: () => import('@/views/information/components/infoForm'),
        hidden: true,
        meta: {
          title: '添加体育资讯&知识'
        }
      }
    ]
  },
  {
    path: '/stuHealthTable',
    component: Layout,
    redirect: '/stuHealthTable',
    children: [{
      path: 'stuHealthTable',
      name: '体育',
      component: () => import('@/views/stuHealthTable/index'),
      meta: {
        title: '体质健康表',
        icon: 'icon-file-excel'
      }
    }]
  },
  {
    path: '/bureauAccount',
    component: Layout,
    name: '局级账户管理',
    meta: {
      title: '局级账户管理',
      icon: 'icon-zuoyejilu'
    },
    children: [{
      path: 'index',
      name: '局级账户管理',
      component: () => import('@/views/bureauAccount/index'),
      meta: {
        title: '局级账户管理'
      }
    }, ]
  },
  {
    path: '/bureauAccounts',
    component: Layout,
    name: '区域经理账户管理',
    meta: {
      title: '区域经理账户管理',
      icon: 'icon-jiangbei'
    },
    children: [{
      path: 'index',
      name: '区域经理账户管理',
      component: () => import('@/views/bureauAccounts/index'),
      meta: {
        title: '区域经理账户管理'
      }
    }, ]
  },
  {
    path: '/spaceManagement',
    component: Layout,
    name: '空间管理',
    meta: {
      title: '空间管理',
      icon: 'el-icon-wind-power'
    },
    children: [{
      path: 'index',
      name: '空间管理',
      component: () => import('@/views/spaceManagement/index'),
      meta: {
        title: '空间管理'
      }
    }, ]
  },
  {
    path: '/source',
    name: '数据驾驶舱',
    component: Layout,
    meta: {
      title: '数据驾驶舱',
      icon: 'icon-jiangbei'
    },
    children: [{
      path: 'index',
      name: '数据驾驶舱',
      component: () => import('@/views/source/index'),
      meta: {
        title: '数据驾驶舱'
      }
    }, ]
  },
  {

    path: '/platformaudit',
    component: Layout,
    name: '审核',
    meta: {
      title: '平台审核',
      icon: 'el-icon-user-solid'
    },
    children: [{
        path: 'jobaudit',
        name: '作业',
        component: () => import('@/views/platformaudit/jobaudit'),
        meta: {
          title: '学习作业审核'
        },
      },
      {
        path: 'followthepracticeaudit',
        name: '跟着练',
        component: () => import('@/views/platformaudit/followthepracticeaudit'),
        meta: {
          title: '跟着练审核'
        },
      },
      {
        hidden: true,
        path: 'sportsknowledgeaudit',
        name: '体育知识',
        component: () => import('@/views/platformaudit/sportsknowledgeaudit'),
        meta: {
          title: '体育知识审核'
        },
      },
    ]
  },
  {
    path: '/sportstest',
    component: Layout,
    meta: {
      title: '设备管理',
      icon: 'icon-shipin'
    },
    children: [
      {
        hidden: false,
        path: 'deviceLsit',
        name: '数据',
        component: () => import('@/views/sportstest/deviceLsit'),
        meta: {
          title: '设备列表'
        },
      },
      {
        hidden: false,
        path: 'vdeostream',
        name: '数据',
        component: () => import('@/views/sportstest/vdeostream'),
        meta: {
          title: '视频流标点'
        },
      },
      {
        hidden: false,
        path: 'dataoverview',
        name: '数据',
        component: () => import('@/views/sportstest/dataoverview'),
        meta: {
          title: '激活码管理'
        },
      },
      {
        hidden: false,
        path: 'equipmentmanagement',
        name: '设备',
        component: () => import('@/views/sportstest/equipmentmanagement'),
        meta: {
          title: '设备信息管理'
        },
      },

    ]
  },
  {
    path: '/newCurriculum',
    component: Layout,
    hidden:true,
    meta: {
      title: '体育课改',
      icon: 'icon-shipin'
    },
    children: [{
        hidden: false,
        path: 'teachingManagement',
        component: () => import('@/layout/components/view/index.vue'),
        meta: {
          title: '教学管理'
        },
        children: [{
            hidden: false,
            path: 'teachingprogramme',
            name: '数据',
            component: () => import('@/views/newCurriculum/teachingManagement/teachingprogramme'),
            meta: {

              title: '教学计划'
            },
          },
          {
            hidden: false,
            path: 'schedulemanagement',
            name: '数据',
            component: () => import('@/views/newCurriculum/teachingManagement/schedulemanagement'),
            meta: {
              title: '进度管理'
            },
          },
        ]
      },




      {
        hidden: false,
        path: 'literacyManagement',
        component: () => import('@/layout/components/view/index.vue'),
        meta: {
          title: '素养管理'
        },
        children: [{
            hidden: false,
            path: 'literacyAllocation',
            name: '素养配置',
            component: () => import('@/views/newCurriculum/literacyManagement/literacyAllocation'),
            meta: {
              title: '素养配置'
            },
          },

          {
            hidden: false,
            path: 'standardConfiguration',  
            name: '标准配置',
            component: () => import('@/views/newCurriculum/literacyManagement/standardConfiguration'),
            meta: {
              title: '标准配置'
            },
          },
          {
            hidden: false,
            path: 'projectConfiguration',
            name: '项目配置',
            component: () => import('@/views/newCurriculum/literacyManagement/projectConfiguration'),
            meta: {
              title: '项目配置'
            },
          },
          {
            hidden: false,
            path: 'underlyingConfiguration',
            name: '基础配置',
            component: () => import('@/views/newCurriculum/literacyManagement/underlyingConfiguration'),
            meta: {
              title: '基础配置'
            },
          },
          {
            hidden: false,
            path: 'statisticalConfiguration',
            name: '统计类配置',
            component: () => import('@/views/newCurriculum/literacyManagement/statisticalConfiguration'),
            meta: {
              title: '统计类配置'
            },
          },
        ]
      },
    ]
  },


  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    //判断是否有标题
    document.title = to.meta.title;
  }
  // 通过requiresAuth判断当前路由导航是否需要登录
  if (to.matched.some(record => record.meta.requiresAuth)) {
    let token = localStorage.getItem('token')
    // 若需要登录访问，检查是否为登录状态
    if (!token) {
      next({
        path: '/login',
        query: {
          redirect: to.fullPath
        }
      })
    } else {
      next()
    }
  } else {
    next() // 确保一定要调用 next()
  }
})
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
